using UnityEngine;

public class PlayerStateBehavior_Opening : AbstractPlayerStateBehavior
{
	public static PlayerStateBehavior_Opening instance;

	private PlayerStateBehavior_Opening()
	{
	}

	public static PlayerStateBehavior_Opening getInstance()
	{
		if (instance == null)
		{
			instance = new PlayerStateBehavior_Opening();
		}
		return instance;
	}

	public override void enter(Player owner)
	{
		base.enter(owner);
		if ((Instance<Court>.instance.homeCourtIndex == UIChooseTeam.indexInTeamData_User && owner.teamType == TeamType.USER) || (Instance<Court>.instance.homeCourtIndex == UIChooseTeam.indexInTeamData_Com && owner.teamType == TeamType.COMPUTER))
		{
			if (MathHelper.isInPercent(50f))
			{
				owner.playAnimation(AnimationName.player_run_opening, 1.3f, 0.8f);
			}
			else
			{
				owner.playAnimation(AnimationName.player_run, 1.2f, 0.8f);
			}
		}
		else
		{
			owner.playAnimation(AnimationName.player_run, 1.2f, 0.8f);
		}
	}

	public override void fixedUpdate(Player owner)
	{
		base.fixedUpdate(owner);
		if (MathHelper.getSqrDistance(owner.getPosition(), (owner.getOffenseDirection() != 0) ? Global.posJumpBall_Left[(int)owner.playerType] : Global.posJumpBall_Right[(int)owner.playerType]) < 4f)
		{
			if (GameHelper.MoveTo(owner, (owner.getOffenseDirection() != 0) ? Global.posJumpBall_Left[(int)owner.playerType] : Global.posJumpBall_Right[(int)owner.playerType], 4f, isLookAtTargetPos: false))
			{
				Instance<Court>.instance.count_ReadyToJumpBall++;
				owner.LookAt(Vector3.zero);
				owner.do_idle();
			}
			owner.LookAtSmooth(Vector3.zero);
		}
		else
		{
			GameHelper.MoveTo(owner, (owner.getOffenseDirection() != 0) ? Global.posJumpBall_Left[(int)owner.playerType] : Global.posJumpBall_Right[(int)owner.playerType], 4f, isLookAtTargetPos: true);
		}
	}

	public override void exit(Player owner)
	{
		base.exit(owner);
		if (owner.playerType == PlayerType.CENTER)
		{
			owner.LookAt(MathHelper.setY(Instance<CameraController>.instance.getCameraPos(), 0f));
		}
	}
}
